//思路：二叉树的所有路径


import java.util.*;
class TreeNode {
     int val;
     TreeNode left;
     TreeNode right;
     TreeNode() {}
     TreeNode(int val) { this.val = val; }
     TreeNode(int val, TreeNode left, TreeNode right) {
         this.val = val;
         this.left = left;
         this.right = right;
     }
 }



 public class Solution {
     List<String> a=new ArrayList<>();
     public List<String> binaryTreePaths(TreeNode root) {
         if(root==null) return a;
         StringBuilder s=new StringBuilder();
         s.append(root.val);
         if(root.left==null&&root.right==null) a.add(s.toString());
         if(root.left!=null) path(root.left,s);
         if(root.right!=null) path(root.right,s);
         return a;
     }
     public void path(TreeNode r,StringBuilder s){
         int size=s.length();
         s.append('-');
         s.append('>');
         s.append(r.val);
         if(r.left==null&&r.right==null){
             a.add(s.toString());
         }
         if(r.left!=null){
             path(r.left,s);
         }
         if(r.right!=null){
             path(r.right,s);
         }
         s.delete(size,s.length());

     }

}